#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll n,q;
ll a[4001][4001];
ll s1[4001][4001];
ll s2[4001][4001]; 
ll calc(ll x,ll y,ll op) {
	if(op==1)
		return x&y;
	if(op==2)
		return x|y;
	if(op==3)
		return x^y;
	if(op==4)
		return (x+y)%999999999;
} 
int main(){
	freopen("fire.in","r",stdin);
	freopen("fire.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=q;i++) {
		ll optt;
		cin>>optt;
		if(optt==1) {
			ll dir;
			cin>>dir;
			if(dir==0) {
				ll x,op,w;
				cin>>x>>op>>w;
				ll sum=0;
				for(int j=1;j<=n;j++) 
					sum=sum+calc(a[x][j],w,op)-a[x][j],a[x][j]=calc(a[x][j],w,op),s1[x][j]+=sum;
			} else {
				ll x,op,w;
				cin>>x>>op>>w;
				ll sum=0;
				for(int j=1;j<=n;j++) 
					sum=sum+calc(a[j][x],w,op)-a[j][x],a[j][x]=calc(a[j][x],w,op),s2[x][j]+=sum;
			}
		} else {
			ll ans=0;
			ll p,q;
			cin>>p>>q; 
			for(int j=1;j<=p;j++)
				ans+=s1[j][q];
			for(int j=1;j<=q;j++) 
				ans+=s2[j][p]; 
			cout<<ans<<'\n';
		}
	}
	return 0;
}



